package com.lq.schoolshop.service.impl;

import com.lq.schoolshop.dao.GoodsMapper;
import com.lq.schoolshop.pojo.Expand.StoreAndGoods;
import com.lq.schoolshop.pojo.Goods;
import com.lq.schoolshop.pojo.Store;
import com.lq.schoolshop.service.GoodsService;
import com.lq.schoolshop.service.StoreService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Author
 * @Date2021/1/7 10:44
 * @Version V1.0
 * 为什么努力？想把钱都赚够，一心跳广场舞曲去。
 **/
@Service
public class GoodsServiceImpl implements GoodsService {

    @Autowired(required = false)
    private GoodsMapper goodsMapper;

    @Autowired
    private StoreService storeService;

    @Override
    public List<Goods> selByall() {
        return goodsMapper.selByall();
    }

    @Override
    public List<Goods> selByName(String name) {
        return goodsMapper.selByName(name);
    }

    @Override
    public int countByTotal() {
        return goodsMapper.countByTotal();
    }

    @Override
    public List<Goods> selByStoreid(int storeid) {
        return goodsMapper.selByStoreid(storeid);
    }

    @Override
    public List<Goods> selById(int id) {
        return goodsMapper.selById(id);
    }

    @Override
    public StoreAndGoods selByGidAndSidAll(int id) {
        List<Goods> goods = goodsMapper.selById(id);
        int storeid = goods.get(0).getStoreid();
        List<Store> stores = storeService.selById(storeid);
        StoreAndGoods storeAndGoods = new StoreAndGoods();
        storeAndGoods.setGoodsList(goods);
        storeAndGoods.setStoreList(stores);
        return storeAndGoods;
    }

    @Override
    public int selCountById(int id) {
        return goodsMapper.selCountById(id);
    }


}
